<template>
  <div class="mv-item" @click="goDetail" v-if="itemData">
    <img class="top-img" :src="itemData.cover.url"/>
    <div class="title one-line">{{ itemData.title }}</div>
    <div class="score" v-if="itemData.rating">
      <div class="score-content">
        <Rankstar :score="Number(itemData.rating.value)"></Rankstar>
        <span class="score-text">{{ itemData.rating.value.toFixed(1) }}</span>
      </div>
    </div>
    <div v-else class="no-score">暂无评分</div>
    <div class="ticket-btn">
      <a :href="'https://movie.douban.com/ticket/redirect/?movie_id=' + itemData.id"
         target="_blank">选座购票</a>
    </div>
  </div>
</template>

<script setup>
import Rankstar from '@/components/rankstar/Rankstar.vue'
import {useRouter} from 'vue-router'
import {defineProps} from 'vue'

const props = defineProps({
  itemData: {
    type: Object,
    default: () => {
    }
  }
})

const router = useRouter()
const goDetail = () => {
  let id = props.itemData.id
  router.push('/detail?id=' + id)
}
</script>

<style lang="less" scoped>
.mv-item {
  margin-left: 10px;
  margin-right: 10px;
  width: 115px;
  display: inline-block;
  margin-bottom: 10px;
  cursor: pointer;
}

.top-img {
  width: 115px;
  height: 161px;
  background-color: #ccc;
}

.title {
  text-align: center;
  color: #333;
  width: 100px;
  margin: 0 auto;
  font-size: 14px;
}

.score-content {
  display: flex;
  width: 77px;
  margin: 0 auto;
  margin-top: 5px;
}

.score-text {
  color: #e09015;
  font-size: 12px;
  margin-left: 6px;
  margin-top: -3px;
}

.no-score {
  margin-top: 2px;
  text-align: center;
}

.ticket-btn {
  background-color: #268dcd;
  border-radius: 2px;
  color: #fff;
  display: block;
  height: 24px;
  line-height: 24px;
  margin: 0 auto;
  text-align: center;
  width: 90px;
}

.ticket-btn a {
  background: none;
  color: #fff;
}

</style>